home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
telecomm
/
uwsrc.arc
/
KERMIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-04-29
|
40KB
|
1,159 lines
#define EXTRADEBUG
/*
* K e r m i t File Transfer Utility seriously hacked for local use with uw
*
* Currently allows only one kermit session to exist in one window concurent.
*
* Adapted from UNIX Kermit, Columbia University, 1981, 1982, 1983
* Bill Catchings, Bob Cattani, Chris Maio, Frank da Cruz, Alan Crosswell
*
* Also: Jim Guyton, Rand Corporation
* Walter Underwood, Ford Aerospace
*
*/
/*
* March 28, 1988
* Hacked into form usable in uw. Converted fsm's to be driven
* by received packet events. Rewrote rpack routine.
*/
#include <obdefs.h>
#include <gemdefs.h>
#include <osbind.h>
#include <stdio.h> /* Standard UNIX definitions */
#include <time.h>
#include "wind.h"
#include "windefs.h"
#define error printmsg
#define chari int /* items of type chari should be char, but, mwc
insists on adjusting them to int anyway */
/* Symbol Definitions */
#define MAXPACKSIZ 94 /* Maximum packet size */
#define SOH 1 /* Start of header */
#define CR 13 /* ASCII Carriage Return */
#define SP 32 /* ASCII space */
#define DEL 127 /* Delete (rubout) */
#define MAXTRY 10 /* Times to retry a packet */
#define MYQUOTE '#' /* Quote character I will use */
#define MYPAD 0 /* Number of padding characters I will need */
#define MYPCHAR 0 /* Padding character I need (NULL) */
#define MYEOL '\r' /* End-Of-Line character I need */
#define MYTIME 10 /* Seconds after which I should be timed out */
#define MAXTIM 60 /* Maximum timeout interval */
#define MINTIM 10 /* Minumum timeout interval */
#ifndef TRUE
#define TRUE -1 /* Boolean constants */
#endif
#define FALSE 0
#define GETPACK 2 /* return constant */
/* Macro Definitions */
/*
* f l u s h i n p u t
*
* Dump all pending input to clear stacked up NACK's.
*/
#define flushinput() /* no explicit call to flush needed for uw */
/*
* tochar: converts a control character to a printable one by adding a space.
*
* unchar: undoes tochar.
*
* ctl: converts between control characters and printable characters by
* toggling the control bit (ie. ^A becomes A and A becomes ^A).
*/
#define tochar(ch) ((ch) + ' ')
#define unchar(ch) ((ch) - ' ')
#define ctl(ch) ((ch) ^ 64 )
#define abs(exp) (((exp) >= 0) ? (exp) : -(exp))
/* Global Variables */
extern int mouse; /* is mouse visible ? */
extern struct wi_str w[];
int size, /* Size of present data */
rpsiz, /* Maximum receive packet size */
spsiz, /* Maximum send packet size */
pad, /* How much padding to send */
reqtimint, /* timeout interval I request */
timint, /* Timeout for foreign host on sends */
n, /* Packet number */
numtry, /* Times this packet retried */
oldtry, /* Times previous packet retried */
image, /* -1 means 8-bit mode */
debug, /* indicates level of debugging output (0=none) */
filnamcnv, /* -1 means do file name case conversions */
filecount, /* Number of files left to send */
kermwdes, /* Window descripter for kermit window */
kermport; /* port number for kermit window */
clock_t timestamp; /* Time last packet was received */
char sflg, rflg; /* flags for RECEIVE, SEND */
char state, /* Present state of the automaton */
padchar, /* Padding character to send */
eol, /* End-Of-Line character to send */
quote, /* Quote character in incoming data */
**filelist, /* List of files to be sent */
*filnam, /* Current file name */
recpkt[MAXPACKSIZ+1], /* Receive packet buffer */
packet[MAXPACKSIZ+1]; /* Packet buffer */
FILE *fp, /* File pointer for current disk file */
*log; /* File pointer for Logfile */
/*
* kerminit
*
* initalization routine - initalize and dispatch to the appropriate routine.
*/
int kerminit(curwin)
int curwin;
{
OBJECT *obj_tmp;
static char path[40] = ".\*.*";
static char file[40] = "";
static char filename[80]; /* space for file and directory */
int butt;
/* Initialize these values and hope the first packet will get across OK */
if (kermwdes && w[kermwdes].kerm_act) return (-1);
kermwdes = curwin;
/* If kermit already active, return. */
w[kermwdes].kerm_act = TRUE; /* mark current window to send output
to kermit instead of emulator */
kermport = find_port(curwin);
eol = CR; /* EOL for outgoing packets */
quote = '#'; /* Standard control-quote char "#" */
pad = 0; /* No padding */
padchar = '\0'; /* Use null if any padding wanted */
timint = MYTIME; /* default timint */
/*
* Set direction and paramaters debug, filnamcnv, image with dialog
*/
rsrc_gaddr(R_TREE, KERMPARM, &obj_tmp);
if (obj_tmp[ASCIIMOD].ob_state == NORMAL &&
obj_tmp[IMAGEMOD].ob_state == NORMAL)
{ /* initalize object and statics */
objc_change(obj_tmp, ASCIIMOD, 0, 0, 0, 0, 0, SELECTED, 0);
objc_change(obj_tmp, CONVNAME, 0, 0, 0, 0, 0, SELECTED, 0);
objc_change(obj_tmp, RECFILE, 0, 0, 0, 0, 0, SELECTED, 0);
path[0] = Dgetdrv() + 'a';
path[1] = ':';
Dgetpath(path+2, 0);
strcat(path, "\\*.*");
}
if ((butt = s_dial(KERMPARM, 3)) == KERMEXIT) return(kermterm());
if (obj_tmp[DEBUGENA].ob_state == SELECTED)
{
debug = obj_tmp[DEBUG1].ob_state + obj_tmp[DEBUG2].ob_state
+ obj_tmp[DEBUG3].ob_state;
}
if (butt == RECFILE) obj_tmp[RECFILE].ob_state = SELECTED;
if (butt == SENDFILE) obj_tmp[SENDFILE].ob_state = SELECTED;
rflg = obj_tmp[RECFILE].ob_state;
sflg = obj_tmp[SENDFILE].ob_state;
image = (obj_tmp[IMAGEMOD].ob_state == SELECTED);
filnamcnv = obj_tmp[CONVNAME].ob_state; /* conversion for UNIX systems */
/* All set up, now execute the command that was given. */
if (debug)
{
printmsg("debuging level = %d\n",debug);
if (sflg) printmsg("Send command\n");
if (rflg) printmsg("Receive command\n");
}
if (sflg) /* Send command */
{
extern char * rindex();
if (!mouse)
{
graf_mouse(M_ON, NULL);
++mouse;
}
fsel_input(path, file, &butt);
if (! butt) return(kermterm());
strcpy(filename, path);
if (debug > 2) printmsg("directory %s", filename);
filnam = rindex(filename, '\\');
if (filnam) *(++filnam) = '\0';
strcat(filename, file);
filnam = filename; /* Get file to send */
if (debug > 2) printmsg("sending %s",filnam);
fp = NULL; /* Indicate no file open yet */
filelist = NULL; /* Set up the rest of the file list */
filecount = 0; /* Number of files left to send */
state = 'S'; /* Send initiate is the start state */
n = 0; /* Initialize message number */
numtry = 0; /* Say no tries yet */
w[kermwdes].kerm_act = TRUE; /* mark current window to send output
to kermit instead of emulator */
timestamp = clock(); /* reset timer */
sendsw();
}
if (rflg) /* Receive command */
{
state = 'R'; /* Receive-Init is the start state */
n = 0; /* Initialize message number */
numtry = 0; /* Say no tries yet */
timestamp = clock(); /* reset timer */
}
return(0);
}
/*
* kermterm - Terminate kermit and tell uw not to call us again.
*/
kermterm()
{
sflg = rflg = 0;
w[kermwdes].kerm_act = FALSE;
kermwdes = 0;
}
kermtimchk()
{
if (!w[kermwdes].kerm_act) /* is ker